# bzip2.cmake
# 本文件包含着从外部导入 bzip2 所需要的信息

SET(BZIP2_SOURCES_DIR "${LIB_SOURCE_DIR}/extern_rocksdb" CACHE PATH "Path to bzip2 sources")
SET(BZIP2_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "bzip2 include directory." FORCE)
SET(BZIP2_LIBRARIES "${LIB_INSTALL_DIR}/libbzip2.a" CACHE FILEPATH "bzip2 include directory." FORCE)

ExternalProject_Add(
        extern_bzip2
        GIT_REPOSITORY https://github.com/libarchive/bzip2.git
        URL https://github.com/libarchive/bzip2/archive/refs/tags/bzip2-1.0.8.tar.gz
        CMAKE_ARGS
        -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX}
        -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
        -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
        BUILD_COMMAND make
)

ADD_LIBRARY(bzip2 STATIC IMPORTED GLOBAL)
SET_PROPERTY(TARGET zlib PROPERTY IMPORTED_LOCATION ${ROCKSDB_LIBRARIES})
ADD_DEPENDENCIES(bzip2 extern_bzip2)